package com.sanben.demand.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sanben.common.web.domain.Result;
import com.sanben.demand.data.dto.DemandDto;
import com.sanben.demand.data.req.DemandReq;
import com.sanben.demand.data.vo.DemandVo;
import com.sanben.demand.service.IDemandService;
import com.sanben.valid.interfaces.First;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * @author cyh
 * @description: 需求咨询表 控制器
 * @date: 2020-08-11
 */
@RestController
@RequestMapping("/demand")
@Api(tags = "需求咨询表相关接口")
public class DemandController {

    @Autowired
    private IDemandService demandService;

    @GetMapping("/home/list")
    @ApiOperation(value = "首页-软件开发咨询")
    public Result<List<DemandVo>> getHomeList() {
        List<DemandVo> list = demandService.getHomeList();
        return Result.data(list);
    }

    @GetMapping("/page")
    @ApiOperation(value = "需求列表")
    public Result<IPage<DemandVo>> page(DemandReq req) {
        IPage<DemandVo> pages = demandService.page(req);
        return Result.data(pages);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "详情", notes = "传入id")
    public Result<DemandVo> detail(@PathVariable Integer id) {
        return Result.data(demandService.detail(id));
    }

    @PostMapping
    @ApiOperation(value = "新增")
    public Result save(@Validated @RequestBody DemandDto dto) {
        return Result.data(demandService.save(dto));
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public Result update(@Validated({First.class, Default.class}) @RequestBody DemandDto dto) {
        return Result.data(demandService.updateById(dto));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public Result remove(@PathVariable List<Integer> ids) {
        return Result.data(demandService.deleteLogic(ids));
    }
}
